<?php
	include(ROOTPATH .'include'. DS .'protect.php');
	include(ROOTPATH .'include'. DS .'checkUserLogin.php');
	$powder_min = 9 ;
	include(ROOTPATH .'include'. DS .'checkPowder.php');
	include "header.php";
	
	$topLen = 200 ;
	
?>
<script type="text/javascript" src="<?php echo JS_PATH;?>admin.sysManage.js"></script>
<link href="<?php echo THEME_PATH ;?>css/admin.css" type="text/css" rel="stylesheet" media="all" />
</head>
<body>
<?php require('top.php'); ?>

<div class="pos">
	
    <div class="contents">
		<?php require('nav.php'); ?>
        <h2 class="title"><?php echo $navigation -> getList();?></h2>
        <div id="sysManage" class="sysManage">
            <h3><a href="#">点击量</a><a href="#">评论量</a><a href="#">文件引用</a><a href="#">附件下载量</a><a href="#">文件收藏次数</a><a href="#">用户登录次数</a><a href="#">用户作品量</a></h3>
            <ul class="hits sysManageDataShowList">
                <li><i class="order">排序</i><span class="counts">总点击量</span>   作品名称</li>                   
                <?php
                    $sql = 'SELECT * FROM `'.DB_PRE .'file` ORDER BY `hits` DESC limit 0,'.$topLen;
                    $lists = $dbs -> select($sql);
                    $i = 0 ;
                    foreach( $lists as $list ){
                        $i++;
                        $id = $encrypt -> code($list['id']);
						$userInfo = $user -> getUser($list['user_id']) ;
                        $nickName = toText($userInfo['nickName'])  ;
                        $userName = toText($userInfo['userName'])
                ?>
                    <li><i class="order"><?php echo $i;?></i><span class="counts"><?php echo $list['hits']; ?></span> <?php
                        echo '<a target="_blank" href="./?option=media&id='.$id .'">'.toText($list['name']) .'</a><a href=""></a>';		
						echo ' <a target="_blank" href="./?option=home&id='.$list['user_id'] .'"><span class="gray">'.$nickName.' ('.$userName.')' .'</span></a>';					
                    ?></li>                   
                <?php
                    }						
                ?>
            </ul><!-- .hits -->
            <ul class="commentsTop sysManageDataShowList">
                <li><i class="order">排序</i><span class="counts">总评论量</span>   作品名称</li>                   
                <?php
                    $sql = 'SELECT * FROM `'.DB_PRE .'file` ORDER BY `comments` DESC limit 0, '.$topLen;
                    $lists = $dbs -> select($sql);
                    $i = 0 ;
                    foreach( $lists as $list ){
                        $i++;
                        $id = $encrypt -> code($list['id']);
						$userInfo = $user -> getUser($list['user_id']) ;
                        $nickName = toText($userInfo['nickName'])  ;
                        $userName = toText($userInfo['userName'])
                ?>
                    <li><i class="order"><?php echo $i;?></i><span class="counts"><?php echo $list['comments']; ?></span> <?php
                        echo '<a target="_blank" href="./?option=media&id='.$id .'">'.toText($list['name']) .'</a>';	
						echo ' <a target="_blank" href="./?option=home&id='.$list['user_id'] .'"><span class="gray">'.$nickName.' ('.$userName.')' .'</span></a>';					
                    ?></li>                   
                <?php
                    }
                ?>
            </ul><!-- .hits -->
            <ul class="refererList sysManageDataShowList">
                <li><i class="order">排序</i><span class="counts">总次数</span>   引用网站网址</li>                   
                <?php
                    $sql = 'SELECT count(*) as `counts`,`referer` FROM `'.DB_PRE .'file_down` GROUP BY `referer`  ORDER BY `id` ';
                    $lists = $dbs -> select($sql);
                    $i = 0 ;
                    foreach( $lists as $list ){
                        $i++;
                ?>
                    <li><i class="order"><?php echo $i;?></i><span class="counts"><?php echo $list['counts']; ?></span>  <?php
                        if( $list['referer'] == 'My')
                            echo '本站';
                        else if( $list['referer'] == '')
                            echo '直接在浏览器中查看或在 flash 中加载';
                        else
                            echo '<a target="_blank" href="'.$list['referer'] .'">'.$list['referer'] .'</a>';						
                    ?></li>                   
                <?php
                    }
                ?>                
            </ul>
            <ul class="fileSourceTop sysManageDataShowList">
                <li><i class="order">排序</i><span class="counts">总下载量</span>   作品名称</li>                   
                <?php
                    $sql = 'SELECT * FROM `'.DB_PRE .'file` ORDER BY `downTimes` DESC limit 0,'.$topLen;
                    $lists = $dbs -> select($sql);
                    $i = 0 ;
                    foreach( $lists as $list ){
                        $i++;
                        $id = $encrypt -> code($list['id']);
						$userInfo = $user -> getUser($list['user_id']) ;
                        $nickName = toText($userInfo['nickName'])  ;
                        $userName = toText($userInfo['userName']);
                ?>
                    <li><i class="order"><?php echo $i;?></i><span class="counts"><?php echo $list['downTimes']; ?></span> <?php
                        echo '<a target="_blank" href="./?option=media&id='.$id .'">'.toText($list['name']) .'</a>';
						echo ' <a target="_blank" href="./?option=home&id='.$list['user_id'] .'"><span class="gray">'.$nickName.' ('.$userName.')' .'</span></a>';						
                    ?></li>                   
                <?php
                    }
                ?>
            </ul><!-- .fileSourceTop -->
            <ul class="favoritesTop sysManageDataShowList">
                <li><i class="order">排序</i><span class="counts">总收藏量</span>   作品名称</li>                   
                <?php
                    $sql = 'SELECT count(*) as `counts`,`file_id` FROM `'.DB_PRE .'favorites` GROUP BY `file_id` ORDER BY `counts` DESC limit 0,'.$topLen;
                    $lists = $dbs -> select($sql);
                    $i = 0 ;
                    foreach( $lists as $list ){
                        $i++;
                        $id = $encrypt -> code($list['file_id']);
						$media = getMedia($list['file_id']);
						if( count( $media) == 0 )
							continue ;
						$userInfo = $user -> getUser($list['user_id']) ;
                        $nickName = toText($userInfo['nickName'])  ;
                        $userName = toText($userInfo['userName']);
                ?>
                    <li><i class="order"><?php echo $i;?></i><span class="counts"><?php echo $list['counts']; ?></span> <?php
                        echo '<a target="_blank" href="./?option=media&id='.$id .'">'.toText($media['name']) .'</a>';
						echo ' <a target="_blank" href="./?option=home&id='.$list['user_id'] .'"><span class="gray">'.$nickName.' ('.$userName.')' .'</span></a>';						
                    ?></li>                   
                <?php
                    }
                ?>
            </ul><!-- .favoritesTop -->
            <ul class="loginTimesTop sysManageDataShowList">
                <li><i class="order">排序</i><span class="counts">登录次数</span>   用户</li>                   
                <?php
                    $sql = 'SELECT * FROM `'.DB_PRE .'user` ORDER BY `loginTimes` DESC limit 0,'.$topLen;
                    $lists = $dbs -> select($sql);
                    $i = 0 ;
                    foreach( $lists as $list ){
                        $i++;
                ?>
                    <li><i class="order"><?php echo $i;?></i><span class="counts"><?php echo $list['loginTimes']; ?></span> <?php
                        echo '<a target="_blank" href="./?option=home&id='.$list['id'] .'">'.toText($list['nickName']) .' ('.toText($list['userName']).')' .'</a>';						
                    ?></li>                   
                <?php
                    }
                ?>
            </ul><!-- .loginTimesTop -->
             <ul class="userFileNumTop sysManageDataShowList">
                <li><i class="order">排序</i><span class="counts">作品数</span>   用户</li>                   
                <?php
                    $sql = 'SELECT count(*) as `counts`,`user_id` FROM `'.DB_PRE .'file` GROUP BY `user_id` ORDER BY `counts` DESC limit 0,'.$topLen;
                    $lists = $dbs -> select($sql);
                    $i = 0 ;
                    foreach( $lists as $list ){
                        $i++;
                        $userInfo = $user -> getUser($list['user_id']) ;
                        $nickName = toText($userInfo['nickName'])  ;
                        $userName = toText($userInfo['userName'])
                ?>
                    <li><i class="order"><?php echo $i;?></i><span class="counts"><?php echo $list['counts']; ?></span> <?php
                        echo '<a target="_blank" href="./?option=home&id='.$list['user_id'] .'">'.$nickName.' ('.$userName.')' .'</a>';						
                    ?></li>                   
                <?php
                    }
                    unset($lists);
                    
                ?>
            </ul><!-- .userFileNumTop -->
       		&nbsp;
        </div><!--#sysManage-->
	</div><!-- .contents-->
</div>
</body>
</html>
